<template>
	<view class="article">
		<view class="article-content" v-if="JSON.parse(JSON.stringify(topics)).length > 0">
			<template v-for="(item, index) in topics">
				<article-item :item="item" :type="item % 2 == 1 ? 'video' : 'images'" :from="fromPage"></article-item>
			</template>
			<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" margin-bottom="45" margin-top="45" color="#C1C0C0" />
		</view>
		<u-empty :text="$t('home.bbs_empty')" mode="list" v-else></u-empty>
		<view class="fixed-publish" @click="$goPage('/article/publish', {}, true)">
			<u-image width="84rpx" height="84rpx" src="/static/images/issue.png" mode=""></u-image>
		</view>
	</view>
</template>

<script>
	import articleItem from "@/components/article-item/index.vue";
  import pageMixin from '@/utils/pageMixin';
  export default {
    mixins: [pageMixin],
		data() {
			return {
				topics:[],
				mine: 0,
				status: 'nomore',
				iconType: 'flower',
				loadText: {
					loadmore: this.$t('home.pull_up'),  
					loading: this.$t('home.loading'),
					nomore: this.$t('home.note_no_more'),
				},
				fromPage:'',
			}
		},

		onLoad(options) {
			this.fromPage = options.type || '';
			if (options.type == 'mine') {
				this.mine = 1;
				uni.setNavigationBarTitle({ title: this.$t('home.my_post')})
			}else {
				uni.setNavigationBarTitle({ title: this.$t('home.bbs')})
			}
		},
		onShow() {
			this.getList()
		},
		components: {
			articleItem
		},
		computed: {
			i18n(){
				return this.$t('home')
			}
		},
		methods: {
			getList() {
				this.$http.get('/bbs/topic/pager/data', {type: 1, mine: this.mine}).then(res => {
					this.topics = res
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.article {
	}
	.article-content {
		overflow: hidden;
	}
	.fixed-publish{
		z-index: 9999;
		position: fixed;
		right: 4rpx;
		bottom: 200rpx;
	}
</style>
